#define fbc -s console -a Resources\libfbpng.a

const MYBPP=32
const SCRX=800,SCRY=600
const SCALE=SCRY/1200
const IMGEXT = ".png"

'#define Render_OpenGL

#include once "windows.bi"
#include once "win\mmsystem.bi"
#include once "fbgfx.bi"
#include "Includes\Enums.bas"

#include "Modules\OpenGL.bas"
#include "Modules\pload.bas"
#include "Modules\Resample.bas"
#include "Modules\Threads.bas"

dim shared as GfxStruct GFX(gmFinal)
dim shared as any ptr BACK
redim as integer TLIST0(0),TLIST1(0)
redim shared as handle TGFX(0)

'SetPriorityClass(GetCurrentProcess,HIGH_PRIORITY_CLASS)
TimeBeginPeriod(1)
ThreadsGet(TLIST0())
screenres SCRX,SCRY,MYBPP
open cons for output as #99
ThreadsGet(TLIST1())
ThreadsGfxUse(TGFX(),TLIST0(),TLIST1())

'BACK = ImageCreate(SCRX,SCRY)
BACK = Pload("Graphics\Back\Wall.png")

scope 'Carregando Imagens alterando tamanho
  dim as fb.image ptr TMPIMG
  dim as integer IX,IY
  dim as string CURPATH
  '"Graphics\Enemy-Foo\Parado\Parado.png"
  #macro ImageLoad(IMGFILE,IMGNUMB,OFFX,OFFY,LPCNT,LPTYPE)    
  TMPIMG=0:TMPIMG=Pload(CURPATH+IMGFILE+IMGEXT)
  if TMPIMG then
    dim as integer TMPX = TMPIMG->Width
    dim as integer TMPY = TMPIMG->Height
    with GFX(IMGNUMB)      
      var ZSCALE = SCALE
      IX=(TMPX*ZSCALE)
      if (IX mod 8) then IX = (IX or 7)+1
      IY=(TMPY*ZSCALE)
      if (IY mod 8) then IY = (IY or 7)+1
      .ImgL = ImageCreate(IX,IY,rgba(0,0,0,0))
      .ImgR = ImageCreate(IX,IY,rgba(0,0,0,0))
      ResamplePut(.ImgR,IX/2,IY/2,TMPIMG,IX,IY-4)            
      ImageDestroy(TMPIMG)      
      for XX as integer = 0 to IX-1
        put .ImgL,(IX-XX,0),.ImgR,(XX,0)-(XX,IY-1),pset
      next XX      
      .SX=IX:.SY=IY
      .OffsetX = OFFX*ZSCALE
      .OffsetY = ((-TMPY)+OFFY)*ZSCALE      
      .LoopCount = LPCNT
      .LoopType = LPTYPE      
    end with
  else
    print #99,"Error Loading: ";CURPATH+IMGFILE+IMGEXT
  end if
  #endmacro
  CURPATH = "Graphics\Enemy-Foo\"
  ImageLoad("Parado\0",gmParado,0,0,0,0)
  ImageLoad("Andando\0",gmAndando,16,0,0,0)
  ImageLoad("Andando\1",gmAndando1,18,1,0,0)
  ImageLoad("Andando\2",gmAndando2,0,0,0,0)
  ImageLoad("Chute\0",gmChute,0,0,0,0)
  ImageLoad("Chute\1",gmChute1,0,0,0,0)
  ImageLoad("Soco\0",gmSoco,0,0,0,0)
  ImageLoad("Soco\1",gmSoco1,0,0,0,0)
end scope

while inkey$ <> ""
  sleep 1
wend

dim as integer DIRE,ACT,OACT,SWP
dim as integer ANI,SPR,FPS,FPMAX
dim as integer DX,DY,PCNT
dim as any ptr PSPR
dim as double BT,POSX,CENX
dim as string TECLA
dim as double TMR,SPD,TMP,SNC
dim as double FPT,LIT

BT = timer:FPT=BT
POSX = SCRX/2


LIT=timer:SNC=LIT
do
  'if (timer-LIT) > 60 then exit do
  TMR = timer  
  
  if PCNT = 0 then ThreadsGfxPause(TGFX()): PCNT += 1
  SetThreadPriority(GetCurrentThread,THREAD_PRIORITY_TIME_CRITICAL)
  
  put (CENX,0),BACK,pset
  put (-SCRX+CENX,0),BACK,pset
  put (SCRX+CENX,0),BACK,pset
  with GFX(SPR)
    DY=550+.OffsetY
    if DIRE = 1 then DX=POSX+.OffsetX-.SX/2:PSPR = .ImgR      
    if DIRE <> 1 then DX=POSX-.OffsetX-.SX/2:PSPR = .ImgL     
    put (DX,DY),PSPR,alpha
    line(DX,DY)-(DX+.SX,DY+.SY),rgb(255,255,255),b,&h5555
    line(DX,DY)-(DX+.SX,DY+.SY),rgb(0,0,0),b,&hAAAA
    line (0,550)-(SCRX,550),rgb(32,64,128),,&h5555
    line (0,550)-(SCRX,550),rgb(128,32,64),,&hAAAA
    line (POSX,0)-(POSX,SCRY),rgb(32,64,128),,&H5555
    line (POSX,0)-(POSX,SCRY),rgb(128,32,64),,&HAAAA
  end with
    
  ACT = caParado
  if multikey(fb.SC_LEFT) then
    if POSX < (SCRX/4) then
      CENX += (SPD*(1.3+ANI/3))
      if CENX >= SCRX then CENX -= SCRX
    else
      POSX -= (SPD*(1.3+ANI/3))
    end if      
    DIRE = -1: ACT = caAndando
  elseif multikey(fb.SC_RIGHT) then    
    if POSX > (SCRX-(SCRX/4)) then
      CENX -= (SPD*(1.3+ANI/3))
      if CENX < 0 then CENX += SCRX      
    else
      POSX += (SPD*(1.3+ANI/3))
    end if
    DIRE = 1: ACT = caAndando
  end if
  
  if ACT<>OACT then ANI=0
  OACT=ACT
  
  if abs(timer-BT) > 1/5 then
    select case ACT
    case caParado
      SPR = gmParado
    case caAndando
      SPR = gmAndando+ANI
      ANI -= 1 ' (ANI+DIRE)
      if ANI >= 3 then ANI -= 3
      if ANI < 0 then ANI += 3      
    end select    
    BT += 1/5
  end if  
    
  sleep 1,1  
  SetThreadPriority(GetCurrentThread,THREAD_PRIORITY_NORMAL)  
  ThreadsGfxResume(TGFX()): PCNT -= 1  
  screensync  
  SNC = timer
    
  FPS += 1
  if (timer-FPT)>= 1 then
    WindowTitle "FightBeta - Fps: " & FPS
    FPMAX=FPS:FPS=0:FPT += 1
  end if
  SPD = (timer-TMR)/(1/60)
  if PCNT=0 then TECLA = inkey$
  
loop until TECLA = chr$(27)


